package view.panel.item
{
	import control.ItemPanelControl;
	import control.panel.IPanelControl;
	
	import events.TabEvent;
	
	import flash.events.MouseEvent;
	
	import utils.DisplayTool;
	
	import view.components.ImgButton;
	import view.components.SimpleLoading;
	import view.components.list.TileList;
	import view.components.tab.Tab;
	import view.components.tab.TabBar;
	import view.panel.AbsPanel;
	
	public class ItemPanel extends AbsPanel
	{
		private var tab:Tab;
		public var shopList:TileList;
		public var ownList:TileList;
		private var loading:SimpleLoading;
		
		public function ItemPanel(panelControl:IPanelControl)
		{
			super(panelControl);
			
			resetBg(300,400,1,true);
			initCloseBut();
			resetCloseBut();
			initTitle("text_title_item");
			
			dropShadow();
			
			
			
			initTweenPanelOpen();
			initTab();
			initList();
			initBut();
			initLoading();
			
			
		}
		
		
		
		private function initLoading():void
		{
			loading = new SimpleLoading();
			loading.x = 150;
			loading.y = 200;
			
			
		}
		
		public function showLoading():void
		{
			loading.start();
			addChild(loading);
		}
		
		public function hideLoading():void
		{
			loading.stop();
			DisplayTool.removeChild(this,loading);
		}
		
		private function initBut():void
		{
			addChild(new ImgButton(40,360,0,onBut,200,25,"butBg",null,"点击进入购买页面"));
		}
		
		private function onBut(event:MouseEvent):void
		{
			(panelControl as ItemPanelControl).onGotoShop();
		}
		
		private function initTab():void
		{
			tab = new Tab();
			tab.addTabBar(new TabBar(0,"道具商城",100),true);
			tab.addTabBar(new TabBar(1,"我的道具",100));
			tab.x = 20;
			tab.y = 30;
			addChild(tab);
			
			tab.addEventListener(TabEvent.TABBAR_CLICK,onTabBarClick);
		}
		
		public function switchToMyItem():void
		{
			tab.selectedIndex = 1;
		}
		
		public function switchToShopItem():void
		{
			tab.selectedIndex = 0;
		}
		
		private function onTabBarClick(event:TabEvent):void
		{
			(panelControl as ItemPanelControl).onTabSwitch(tab.selectedIndex);
			
			if (tab.selectedIndex == 1)
			{
				shopList.visible = false;
				ownList.visible = true;
			}
			else
			{
				shopList.visible = true;
				ownList.visible = false;
			}
		}
		
		
		private function initList():void
		{
			shopList = new TileList(278,282,new ItemShop());
			shopList.x = 10;
			shopList.y = 60;
			shopList.drawBg();
			addChild(shopList);

			
			ownList = new TileList(278,282,new ItemOwn());
			ownList.x = shopList.x;
			ownList.y = shopList.y;
			ownList.drawBg();
			addChild(ownList);
			
			ownList.visible = false;
		}
	}
}